package com.file.manage.domain.service.impl;


import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.file.manage.domain.entity.FolderStencil;
import com.file.manage.domain.request.SaveFolderStencilRequest;
import com.file.manage.domain.service.FolderStencilService;
import com.file.manage.infrastructure.base.service.impl.BaseServiceImpl;
import com.file.manage.infrastructure.dao.impl.FolderStencilDaoImpl;
import org.springframework.stereotype.Service;

/**
 * @author H41
 * @Type FolderStencilServiceImpl.java
 * @date 2025/6/1 1:16
 * @Desc
 */
@Service
public class FolderStencilServiceImpl extends BaseServiceImpl<FolderStencilDaoImpl, FolderStencil> implements FolderStencilService {
    @Override
    public void saveFolderStencil(SaveFolderStencilRequest request) {
        if (StrUtil.isEmpty(request.getId())) {
            FolderStencil folderStencil = new FolderStencil();
            folderStencil.setName(request.getName());
            folderStencil.setParentLevel(request.getParentLevel());
            this.save(folderStencil);
        } else {
            FolderStencil folderStencil = baseDao.getById(request.getId());
            Assert.notNull(folderStencil, "文件夹模板不存在");
            folderStencil.setName(request.getName());
            folderStencil.setParentLevel(request.getParentLevel() + 1);
            this.updateById(folderStencil);
        }
    }
}
